<?php

namespace App\Console\Commands;

use App\Models\Order;
use Carbon\Carbon;
use Illuminate\Console\Command;

class CloseOrder extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'order:close';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'close order by id';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $order_id = $this->ask(trans('command.please_enter') . ' order_id');

        $order = Order::find($order_id);

        $job = (new \App\Jobs\CloseOrder($order))
            ->delay(Carbon::now()->addMinutes(1));

        dispatch($job);
    }
}
